package com.hualan.sfzy.controller.counselor;

import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.CounselorComment;
import com.hualan.sfzy.service.counselor.CounselorCommentService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/CounselorComment")
public class CounselorCommentController {
    @Autowired
    private CounselorCommentService service;
    @PostMapping
    public Result add(@RequestBody CounselorComment entity){
        int num = service.add(entity);
        return num > 0 ? Result.success() : Result.error();
    }
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = service.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }
    @DeleteMapping
    public Result removeBatch(Integer[] ids){
        int num = service.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }
    @PutMapping
    public Result edit(@RequestBody CounselorComment entity){
        int num = service.edit(entity);
        return num > 0 ? Result.success() : Result.error();
    }
    @GetMapping
    public Result find(){
        List<CounselorComment> list = service.find();
        return Result.success(list);
    }
    @GetMapping("/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM, required = false,
                    defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE, required = false,
                    defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize, CounselorComment entity)
    {
        Map<String, Object> map = service.findPage(pageNum, pageSize,
                entity);
        return Result.success(map);
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        CounselorComment entity = service.findById(id);
        return Result.success(entity);
    }
}
